const UserModel = require("../../models/UserModel");
const UserService = {
    login: async ({ username, password }) => {
        // 登录逻辑
        return UserModel.find({ username, password });
    },
    upload: async ({ id, username, gender, introduction, avatar }) => {
        if (avatar) {
            return UserModel.updateOne({
                _id: id
            }, {
                username,
                gender,
                introduction,
                avatar
            });
        } else {
            return UserModel.updateOne({
                _id: id
            }, {
                username,
                gender,
                introduction
            });
        }

    },
    addUser: async ({ username, password, gender, introduction, avatar, role, deleted }) => {
        return UserModel.create({ username, password, gender, introduction, avatar, role, deleted })
    },
    findUserList: async () => {
        return UserModel.find({ deleted: false });
    },
    deleteUser: async (id) => {
        console.log(id)
        return UserModel.updateOne({
            _id: id
        }, {
            deleted: true
        });
    },
    updateUser: async ({ _id, username, password, introduction, role }) => {
        console.log(_id, username, password, introduction, role)
        return UserModel.updateOne({ _id }, {
            username, password, introduction, role
        });
    }
}
module.exports = UserService;